package com.springcloud.xxkfz.controller;

import com.springcloud.xxkfz.convert.ProductConvert;
import com.springcloud.xxkfz.entity.Product;
import com.springcloud.xxkfz.service.ProductService;
import com.springcloud.xxkfz.vo.ProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     * 查询列表数据
     *
     * @return
     */
    @GetMapping("/list")
    public List<ProductVO> list() {
        List<Product> productList = productService.list();
        return ProductConvert.INSTANCE.toVO(productList);
    }

    /**
     * 根据id获取数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ProductVO getProductById(@PathVariable("id") String id) {
        return ProductConvert.INSTANCE.to2VO(productService.getById(id));
    }

    /**
     * 根据id删除数据
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable("id") String id) {
        boolean isDelFlag = productService.removeById(id);
        return isDelFlag;
    }
}
